@echo off
chcp 65001 >nul
echo ====================================
echo   安装依赖
echo ====================================
echo.

echo [0] 安装根目录依赖...
call pnpm install
if %errorlevel% neq 0 (
    echo [错误] 根目录依赖安装失败
    pause
    exit /b 1
)

echo [0.1] 重建 better-sqlite3 原生模块...
call pnpm rebuild better-sqlite3
if %errorlevel% neq 0 (
    echo [警告] better-sqlite3 重建失败，可能需要安装编译工具
    echo [提示] 请确保已安装：
    echo   1. Python 3.x
    echo   2. Visual Studio Build Tools
    echo   3. 或运行: npm install -g windows-build-tools
)

echo.
echo [1] 安装 API 服务依赖...
cd api
call pnpm install
if %errorlevel% neq 0 (
    echo [错误] API 服务依赖安装失败
    cd ..
    pause
    exit /b 1
)
cd ..

echo.
echo [2] 安装 Admin 服务依赖...
cd admin
call pnpm install
if %errorlevel% neq 0 (
    echo [错误] Admin 服务依赖安装失败
    cd ..
    pause
    exit /b 1
)
cd ..

echo.
echo [3] 安装管理后台前端依赖...
cd admin-frontend
call pnpm install
if %errorlevel% neq 0 (
    echo [错误] 管理后台前端依赖安装失败
    cd ..
    pause
    exit /b 1
)
cd ..

echo.
echo ====================================
echo   依赖安装完成！
echo ====================================
pause

